package com.system.vote.common.utils;


import java.util.Random;
import java.util.regex.Pattern;

/**
 * 判断邮箱格式是否正确
 *
 * @param email
 * @return false或者true
 */
public class MailUtils {
    /**
     * 生成随机的六位验证码
     */
    public StringBuilder CreateCode(int number) {
        String dates = "0123456789";
        StringBuilder code = new StringBuilder();
        Random r = new Random();
        for (int i = 0; i < number; i++) {
            int index = r.nextInt(dates.length());
            char c = dates.charAt(index);
            code.append(c);
        }
        return code;
    }

    public boolean isEmail(String email) {
        if (email == null || email.length() < 1 || email.length() > 256) {
            return false;
        }
        Pattern pattern = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
        return pattern.matcher(email).matches();
    }

}
